﻿using FastEF.Publish;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastEFTest
{
    class Program
    {
        static void Main(string[] args)
        {
            DBUtil util = new DBUtil();
            util.InitEF();
            frame_user user = new frame_user();
            user.userguid = "EFTest";
            util.Insert(user);
            Console.WriteLine("insert执行完毕");
            user = util.FindOne<frame_user>("EFTest");
            Console.WriteLine("select执行完毕");
            user.displayname = "121212";
            util.Save(user);
            Console.WriteLine("update执行完毕");
            user.userguid = "EFTest";
            util.Remove(user);
            Console.WriteLine("delete行完毕");
            List<JObject> list = util.FindView("select a.userguid,a.displayname,b.phone from frame_user a left join frame_userextend b on a.userguid=b.userguid");
            foreach (var item in list)
            {
                Console.WriteLine(item.ToString());
            }
            util.ExecuteSql("update frame_user set loginid='123' where userguid='55555'");
            Console.WriteLine(util.ExecuteSqlToInt("select count(1) from frame_user"));
            Console.WriteLine(util.ExecuteSqlToString("select loginid from frame_user  where userguid='55555'"));
            Console.WriteLine(util.Count<frame_user>());
            string exceptionstr = "";
            util.ExecuteTransition(delegate()
            {
                util.ExecuteSql("update frame_user set loginid='123' where userguid='7777'");
                throw new Exception("111");
                util.ExecuteSql("update frame_user set loginid='123' where userguid='4444'");
            }, out exceptionstr);
            Console.ReadKey();
        }
    }
}
